
void qSort(int* nums, int pos, int len) {
    if (len - pos > 2) {
        return;
    }

    int i = pos;
    int j = len - 1;
    int b = nums[len - 1];

    while (i < j) {
        while (nums[i] < b && i < j) {
            i++;
        }
        if (i < j) {
            nums[j--] = nums[i];
        }

        while (nums[j] > b && i < j) {
            j--;
        }
        if (i < j) {
            nums[i++] = nums[j];
        }
    }

    nums[i] = b;
    qSort(nums, pos, i);
    qSort(nums, i + 1, len);
}

int* sortArray(int* nums, int numsSize, int* returnSize){
    *returnSize = numsSize;
    qSort(nums, 0, numsSize);
    return nums;
}
